export function getMarketList(){ 
  return [
    { symbol:'BTC/USDT', market:'spot', price:52000, change:1.2 },
    { symbol:'ETH/USDT', market:'spot', price:3400, change:-0.5 },
    { symbol:'SOL/USDT', market:'deriv', price:140, change:2.1 },
    { symbol:'BNB/USDT', market:'spot', price:420, change:0.8 },
    { symbol:'XRP/USDT', market:'spot', price:0.98, change:-1.5 },
    { symbol:'LTC/USDT', market:'deriv', price:80, change:0.3 },
    { symbol:'DOGE/USDT', market:'spot', price:0.14, change:5.6 },
    { symbol:'ADA/USDT', market:'spot', price:0.38, change:-0.9 },
    { symbol:'ATOM/USDT', market:'spot', price:8.5, change:0.2 },
    { symbol:'AVAX/USDT', market:'deriv', price:25.6, change:-0.4 }
  ]
}

export function getVolatilityData(asset='BTC', range='1M'){
  const now = new Date()
  let len = { '1D':24, '1W':7, '1M':30, '3M':90 }[range] || 30
  const points = []
  for(let i = len-1; i >= 0; i--){
    const d = new Date(now)
    if(range==='1D'){ d.setHours(now.getHours()-i); points.push({ date: d.getHours()+':00', value: +(Math.random()*8 + (asset==='ETH'?25:20)).toFixed(2) }) }
    else{ d.setDate(now.getDate()-i); points.push({ date: d.toISOString().slice(0,10), value: +(Math.random()*12 + (asset==='ETH'?30:20)).toFixed(2) }) }
  }
  return points
}

export function getKlineData(asset='BTC', range='1M'){
  const now = new Date()
  const len = 60
  const out = []
  let price = asset==='ETH'?3000:50000
  for(let i = len-1; i >= 0; i--){
    const d = new Date(now); d.setDate(now.getDate()-i)
    const open = +(price + (Math.random()-0.5)*200).toFixed(2)
    const close = +(open + (Math.random()-0.5)*400).toFixed(2)
    const low = Math.min(open, close) - +(Math.random()*50).toFixed(2)
    const high = Math.max(open, close) + +(Math.random()*50).toFixed(2)
    out.push([d.toISOString().slice(0,10), open, close, low, high])
    price = close
  }
  return out
}

export function calcMA(values, dayCount){
  const closes = values.map(v=>v[2])
  const res = []
  for(let i=0;i<closes.length;i++){
    if(i<dayCount-1){ res.push('-') }
    else{
      const slice = closes.slice(i-dayCount+1, i+1)
      const sum = slice.reduce((a,b)=>a+b,0)
      res.push(+(sum/dayCount).toFixed(2))
    }
  }
  return res
}
